package com.ldy.transmit.config;

import com.ldy.transmit.common.util.AppUtil;
import com.ldy.transmit.interceptor.LdyHttpRequestInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

/**
 * 描述：配置类
 */
@Configuration
//@ImportResource(locations = {"classpath:/spring/*.xml"})
public class config {
    private AppUtil appUtil=new AppUtil();
    @Autowired
    private LdyHttpRequestInterceptor ldyHttpRequestInterceptor;
    // 声明为Bean，方便应用内使用同一实例
    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();

        // 把自定义的ClientHttpRequestInterceptor添加到RestTemplate，可添加多个
        restTemplate.setInterceptors(Collections.singletonList(ldyHttpRequestInterceptor));
        return restTemplate;
    }

    @Bean
    public AppUtil AppUtil(){
        return appUtil;
    }// <bean id="appUtil" class="com.sf.aesp.owsp.mobile.util.AppUtil" scope="singleton"/>
}
